package com.zerui.manager.web;

import com.zerui.cola.dto.Response;
import com.zerui.cola.dto.SingleResponse;
import com.zerui.manager.web.cmd.DeviceGroupAddCmd;
import com.zerui.manager.web.cmd.DeviceGroupMoveCmd;
import com.zerui.manager.web.cmd.DeviceGroupUpdateCmd;
import com.zerui.manager.web.vo.DeviceGroupVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.constraints.NotNull;

/**
 * @Author wh
 * @create_time 2023-08-23 15:33
 */
@Validated
@Api(value = "设备分组管理", tags = "门禁设备管理")
@RestController
@RequestMapping("/api/v1/group")
public class DeviceGroupController {

    @Resource
    private DeviceGroupService deviceGroupService;

    @ApiOperation(value = "添加", tags = "设备分组")
    @PostMapping
    public Response add(@RequestBody @Validated DeviceGroupAddCmd deviceGroupAddCmd) {
        return deviceGroupService.add(deviceGroupAddCmd);
    }

    @ApiOperation(value = "修改", tags = "设备分组")
    @PutMapping
    public Response update(@RequestBody @Validated DeviceGroupUpdateCmd deviceGroupUpdateCmd) {
        return deviceGroupService.update(deviceGroupUpdateCmd);
    }

    @ApiOperation(value = "删除", tags = "设备分组")
    @PostMapping("/delete/{id}")
    public Response deleteByIds(@PathVariable("id") @NotNull(message = "分组id不能为空") Long id) {
        return deviceGroupService.deleteById(id);
    }

    @ApiOperation(value = "移动", tags = "设备分组")
    @PostMapping("/move")
    public Response move(@RequestBody @Validated DeviceGroupMoveCmd deviceGroupMoveCmd) {
        return deviceGroupService.move(deviceGroupMoveCmd);
    }

    @ApiOperation(value = "分组列表", tags = "设备分组")
    @GetMapping("/group/list")
    public SingleResponse<DeviceGroupVO> deviceGroupList() {
        return deviceGroupService.deviceGroupList();
    }

}
